from jyutils import *
#~ import imp,os.path
#~ def _import_(filename):
def test_easy_call():
    def func(a,b,c='default',d='default'):
        return repr([a,b,c,d])
    def call1():
        a=1
        b=1
        return easy_call(func)

    assert(call1()==repr([1,1,'default','default']))
    def call2():
        a=1
        b=1
        c=33
        return easy_call(func)
    assert(call2()==repr([1,1,33,'default']))
    class T:
        def func(self,a,b,c='default',d='default'):
            a=1
            b=1
            return repr([a,b,c,d])
        @classmethod
        def cls_func(self,a,b,c='default',d='default'):
            a=1
            b=1
            return repr([a,b,c,d])
        @staticmethod
        def static_func(a,b,c='default',d='default'):
            a=1
            b=1
            return repr([a,b,c,d])
    y=T()
    def call_method():
        a=1
        b=1
        return easy_call(y.func)
    assert(call_method()==repr([1,1,'default','default']))
    def call_cls_method():
        a=1
        b=1
        return easy_call(y.cls_func)
    assert(call_cls_method()==repr([1,1,'default','default']))
    def call_static_method():
        a=1
        b=1
        return easy_call(y.static_func)
    assert(call_static_method()==repr([1,1,'default','default']))
if __name__ == '__main__':
    test_easy_call()
    import sys
    sys.exit(0)
    def argspec(f):
        import types
        i=inspect.getfullargspec(f)
        print('='*8,f.__name__,'='*8)
        print(type(f) is types.FunctionType, type(f) is types.MethodType)
        print(f.__name__,i.defaults,i,type(i.defaults))
        print(type(f))
        import types
        if type(f) is types.MethodType:
            print('True',f.__self__)
        else:
            print('HHH')

        if type(i.defaults) is tuple:
            print(i.args[0-len(i.defaults):],len(i.args),len(i.defaults))
        print('='*8,f.__name__,'='*8)
    import platform
    class T:
        def myfunc(self,f):

            print(self,f)
            pass
        @classmethod
        def cls_method(cls,x):
            print(T.cls_method,cls,x)
            pass
        @staticmethod
        def static_method(cls,x):
            print(T.static_method,cls,x)
            pass

    def f(a,b,*args,d=None,c=None,**kwargs):
        print(a,b)
        print(c,d)
        print(args,kwargs)
    def g(a,b,c=None,d=None,e=platform.node()):
        print(a,b,c)
        pass
    def h(a,b,c):
        print(a,b,c)
        pass
    def e(a=None,b=None):
        pass
    print(inspect.getfullargspec(f))
    g(b=15,a=3)
    #~ g(c=17)
    argspec(g)
    argspec(f)
    argspec(T().myfunc)
    argspec(T().cls_method)
    argspec(T().static_method)
    T().myfunc(123)
    T().cls_method(123)
    T().static_method(123,1)
    #~ print(inspect.getfullargspec(g),inspect.getfullargspec(g).count())
    #~ print(inspect.getargspec(g))
    #~ print(inspect.getfullargspec(h),inspect.getfullargspec(h).count())
    #~ print(inspect.getfullargspec(e))
